package com.dmcloud.service;

import com.dmcloud.entity.Price;
import com.dmcloud.mapper.PriceMapper;
import com.dmcloud.order.fegin.IOrderClient;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by xiaodao
 * date: 2020/3/31
 */
@Service
@Slf4j
public class PriceService {

    @Autowired
    private PriceMapper priceMapper;

    @Autowired
    private IOrderClient iOrderClient;



    public void save(Price price){
        priceMapper.insert(price);
    }

    public void updatebyNmae(Price price){
        priceMapper.updateNameById(price);
    }


    @GlobalTransactional(name = "test-create-order",rollbackFor = Exception.class)
    public void testTranscation(Price price){
        log.info("插入本地的数据 id: {}",price.getId());
        priceMapper.insert(price);
        log.info("插入本地成功");

        iOrderClient.createOrder("8");

        System.out.println(1/0);
    }

}
